package net.seabook.games.tetris.model;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;

import javax.swing.JComponent;

import net.seabook.games.tetris.ui.CanvasPanel;

public class SettingSystem extends JComponent implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private int level;
	private int totalScore;
	private int lines;
	
	private boolean drawGrid = true;
	private boolean stopped = false;

	private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);

	public enum Score {
		A(10), B(25), C(40), D(60);

		private int score;

		private Score(int score) {
			this.score = score;
		}

		public int getScore() {
			return score;
		}

	}

	public int getLevelSpeed() {
		return CanvasPanel.SPEED - level * 80;
	}

	public int getLevel() {
		if (lines == 0) return 1;
		
		return lines / 10 + 1;
	}
	
	public String wrapperLevel() {
		return String.valueOf(getLevel());
	}

	public void setLevel(int level) {
		int old = this.level;
		this.level = level;
		this.pcs.firePropertyChange("level", old, level);
	}

	public int getTotalScore() {
		return totalScore;
	}
	
	public String wrapperTotalScore() {
		return String.valueOf(getTotalScore());
	}

	public void setTotalScore(int totalScore) {
		int old = this.totalScore;
		this.totalScore = totalScore;
		this.pcs.firePropertyChange("totalScore", old, totalScore);
	}

	public int getLines() {
		return lines;
	}
	
	public String wrapperLines() {
		return String.valueOf(getLines());
	}

	public void setLines(int lines) {
		int old = this.lines;
		this.lines = lines;
		this.pcs.firePropertyChange("lines", old, lines);
	}

	public void addPropertyChangeListener(PropertyChangeListener listener) {
		this.pcs.addPropertyChangeListener(listener);
	}

	public void removePropertyChangeListener(PropertyChangeListener listener) {
		this.pcs.removePropertyChangeListener(listener);
	}

	public boolean isDrawGrid() {
		return drawGrid;
	}

	public void setDrawGrid(boolean drawGrid) {
		this.drawGrid = drawGrid;
	}

	public boolean isStopped() {
		return stopped;
	}
	
	public void setStopped(boolean stopped) {
		this.stopped = stopped;
	}

}
